package com.example.demo_dongruanD.service.impl;

import com.example.demo_dongruanD.pojo.OverAllResult;
import com.example.demo_dongruanD.repository.OverAllResultRepository;
import com.example.demo_dongruanD.service.OverAllResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class OverAllResultServiceImpl implements OverAllResultService {

    private final OverAllResultRepository repository;

    @Autowired
    public OverAllResultServiceImpl(OverAllResultRepository repository) {
        this.repository = repository;
    }

    @Autowired
    private OverAllResultRepository overAllResultRepository;

    @Override
    public List<OverAllResult> getOverallResultsByOrderId(Integer orderId) {
        return overAllResultRepository.findByOrderId(orderId);
    }
    @Override
    public OverAllResult saveOrUpdate(OverAllResult result) {
        return repository.save(result);
    }


    @Override
    public OverAllResult findById(Integer id) {
        Optional<OverAllResult> result = repository.findById(id);
        return result.orElse(null);
    }

    @Override
    public void delete(Integer id) {
        repository.deleteById(id);
    }
}
